<template>
  <AdminLayout>
    <el-table
      empty-text="暂无数据"
      :data="TableData"
      v-loading="isLoading"
      style="width: 100%"
    >
      <el-table-column label="日期">
        <template #default="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名">
        <template #default="scope">
          <el-popover effect="light" trigger="hover" placement="top">
            <template #default>
              <p>姓名: {{ scope.row.name }}</p>
              <p>住址: {{ scope.row.address }}</p>
            </template>
            <template #reference>
              <div class="name-wrapper">
                <el-tag size="medium">{{ scope.row.name }}</el-tag>
              </div>
            </template>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </AdminLayout>
</template>

<script>
import { mapActions, mapState } from "vuex";

export default {
  computed: {
    ...mapState("tableData", ["TableData"]),
  },

  data() {
    return {
      isLoading: true,
    };
  },
  async created() {
    this.isLoading = true;
    try {
      await this.GetTable();
      // console.log(this.GetTable)
    } catch (e) {
      this.$message.error("网络错误");
      // console.log(e)
    } finally {
      this.isLoading = false;
      // console.log(123)
    }

    /*axios({
      url:"http://localhost:3000/tableData",
    }).then(res => {
      console.log(res.data)
    })*/
  },
  methods: {
    ...mapActions("tableData", ["GetTable"]),
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
  },
};
</script>

<style lang="stylus">
.el-header
  border-bottom  1px solid #545c64
  text-align center
</style>
